package cn.foo.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * 定义切面类
 * @author Frank
 * @date 07-05
 */
@Component
@Aspect
public class UserServiceLogger {
    @Before(value = "execution(* cn.foo.service..*.*(..))")
    public void before(JoinPoint joinPoint){
        System.out.println("在调用："+joinPoint.getTarget()
                +"的"+joinPoint.getSignature().getName()
                +"方法前记录日志，方法参数："+ Arrays.toString(joinPoint.getArgs()));
    }
    @AfterReturning(value = "execution(* cn.foo.service..*.*(..))",returning = "result")
    public void afterReturning(JoinPoint joinPoint,Object result){
        System.out.println("在调用："+joinPoint.getTarget()
                +"的"+joinPoint.getSignature().getName()
                +"方法之后记录日志，方法返回值："+ result);
    }
}
